<template>
  <div class="user1-page">
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="项目名称：">
          <el-input clearable v-model="searchParams.projectName" />
        </el-form-item>
        <el-form-item label="联报类型：">
          <el-select clearable v-model="searchParams.gtype">
            <el-option v-for="item in options1" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="服务状态：">
          <el-select clearable v-model="searchParams.status">
            <el-option v-for="item in options2" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-box">
      <el-table
        v-loading="loading"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="附件资料">
          <template slot-scope="scope">
            <ClickDownload :file="scope.row.file"/>
          </template>
        </el-table-column>
        <el-table-column label="服务状态">
          <template slot-scope="scope">
            <el-tag :type="scope.row.statusType">{{ scope.row.statusName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="服务方式" prop="solutionName" />
        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button type="text" @click="onRead(scope.row)">查看</el-button>
            <el-button type="text" @click="onDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <LineAdd ref="LineAddRef" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import LineAdd from './line-add'
import { http_accurate } from '@/api'
import { serve_way, handleStatus } from '@/dict'
export default {
  name: 'Index',
  props: {
    projectId: String
  },
  components: {
    LineAdd
  },
  mixins: [crud],
  data() {
    return {
      request: http_accurate.line,
      searchParams: {
        projectName: '',
        gtype: '',
        status: ''
      },
      options1: [
        { value: 1, name: '通水' },
        { value: 2, name: '通电' },
        { value: 3, name: '通气' },
        { value: 4, name: '通网络' }
      ],
      options2: handleStatus,
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'createTime', label: '提交时间' },
        { prop: 'gtypeName', label: '联报类型' }
      ],
      tableData: [
      ]
    }
  },
  methods: {
    getQueryParams() {
      const params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        ...this.searchParams,
        projectId: this.projectId
      }
      return params;
    },
    formatTableData(data) {
      data.forEach(el => {
        el.gtypeName = this.options1.find(item => item.value == el.gtype)?.name
        el.statusName = this.options2.find(item => item.value == el.status)?.name
        el.statusType = this.options2.find(item => item.value == el.status)?.type
        el.solutionName = serve_way[el.solution]
      })
    },
    onRead(item) {
      this.$refs.LineAddRef.open(item)
    }
  }
}
</script>

<style scoped lang="scss">
</style>
